#include <iostream>
#include <string>
#include <unordered_map>
#include <cmath>
using namespace std;
int wordToNumber(const string& word) {
    static unordered_map<string, int> wordMap = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    return wordMap[word];
}
bool isPrime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}
int main() {
    string input;
    getline(cin, input);
    string word;
    string numberStr;
    for (char c : input) {
        if (c == ' ') {
            int number = wordToNumber(word);
            numberStr += to_string(number);
            word = "";
        }
        else {
            word += c;
        }
    }
    int number = wordToNumber(word);
    numberStr += to_string(number);
    if (numberStr.length() != 3 || !isdigit(numberStr[0]) || !isdigit(numberStr[1]) || !isdigit(numberStr[2])) {
        cout << "Wrong input" << endl;
        return 0;
    }
    int num = stoi(numberStr);
    int closestPrime = num;
    int diff = 0;
    while (true) {
        if (isPrime(closestPrime - diff)) {
            cout << closestPrime - diff << endl;
            break;
        }
        if (isPrime(closestPrime + diff)) {
            cout << closestPrime + diff << endl;
            break;
        }
        ++diff;
    }
    return 0;
}